< previous page page_619 next page >

Page 619
these intersections, check the value of the parameter u corresponding to the intersection. Because the vector W is created with two points P1 and P2 that lie on the ends of the cylinder, u is between 0.0 and 1.0 if the corresponding point I in Figure 17.18 lies within the cylinder. If u < 0.0 or u > 1.0, the point of intersection is not on the finite portion of the cylinder, so you can ignore it.
This method does nothing to handle the ends of the cylinder. If you want the cylinder to be solid, create two RayDisk objects to cap the ends.
If you want the cylinder to be hollow so that you can look into its interior, you need to modify the intersection routine to examine both values of t. If the value closer to the center of projection lies outside the finite part of the cylinder, you need to consider the other value for t. If that value lies on the finite cylinder, the ray is reaching it through the inside of the cylinder, and it should be visible.
The RayCylinder class used by program VRay manages finite cylinders that are not hollow. The following code shows how the FindT function locates the cylinder's point of intersection with a ray.
e10a6a0a59f035e870d90cca05b85fce.gif
' Return the value T for the point of intersection
' between the vector from point (px, py, pz) in
' the direction <wx, wy, wz>.
'
' direct_calculation is true if we are finding the
' intersection from a viewing position ray. It is
' false if we are finding a reflected intersection
' or a shadow feeler.
Public Function RayTraceable_FindT( _
    ByVal direct_calculation As Boolean, ByVal px As Single, _
    ByVal py As Single, ByVal pz As Single, _
    ByVal Vx As Single, ByVal Vy As Single, _
    ByVal Vz As Single) As Single
Dim x1 As Single
Dim y1 As Single
Dim z1 As Single
Dim Wx As Single
Dim Wy As Single
Dim Wz As Single
Dim w_len_squared As Single
Dim WdotV As Single
Dim A As Single
Dim B As Single
Dim Cx As Single
Dim Cy As Single
Dim Cz As Single
Dim dx As Single
Dim dy As Single
Dim dz As Single
Dim A1 As Single
Dim b1 As Single
Dim C1 As Single

 
< previous page page_619 next page >